from rest_framework import serializers
from rest_framework.pagination import PageNumberPagination

from apps.activitys.models import Gathering
from apps.users.models import User
from apps.users.serializers import UserRegSerializer

class PageNum(PageNumberPagination):
    page_size = 6
    page_size_query_param = 'pagesize'
    max_page_size = 6

    # def get_paginated_response(self, data):
    #   return Response({
    #     'count': self.page.paginator.count,  # 总数量
    #     'lists': data,  # 用户数据
    #     'page': self.page.number,  # 当前页数
    #     'pages': self.page.paginator.num_pages,  # 总页数
    #     'pagesize': self.page_size  # 后端指定的页容量
    #   })


class ActivitySerializer(serializers.ModelSerializer):

    #user = UserRegSerializer(many=True)
    #user= serializers.PrimaryKeyRelatedField(label='图书', read_only=True)
    # 关联对象嵌套序列化字段
    users = serializers.PrimaryKeyRelatedField(read_only=True, many=True)

    class Meta:
        model=Gathering
        #fields='__all__'
        fields = ('id','name','image','city','starttime','endrolltime','users')

class ActivityDetailSerializer(serializers.ModelSerializer):

    #user = UserRegSerializer(many=True)
    #user= serializers.PrimaryKeyRelatedField(label='图书', read_only=True)
    # 关联对象嵌套序列化字段
    users = serializers.PrimaryKeyRelatedField(read_only=True, many=True)#

    class Meta:
        model=Gathering
        fields='__all__'



